package com.lalosoft.misgastos.dao;

import java.sql.SQLException;
import java.util.List;

import android.content.Context;
import android.util.Log;

import com.j256.ormlite.android.apptools.OpenHelperManager;
import com.lalosoft.misgastos.config.DatabaseHelper;
import com.lalosoft.misgastos.domain.Item;

public class ItemDao implements AbstractDao<Item> {
	
	private static String TAG = "ItemDao";
	
	private DatabaseHelper helper;
	
	public ItemDao(Context context){
		OpenHelperManager.setOpenHelperClass(DatabaseHelper.class);
		helper = (DatabaseHelper)OpenHelperManager.getHelper(context);
	}

	@Override
	public void delete(Item object) {
		try {
			helper.getItemDao().delete(object);
		} catch (SQLException e) {
			Log.e(TAG, "ERROR ITEMDAO: " + e.getMessage(), e);
		}
	}

	@Override
	public List<Item> findAll() {
		List<Item> list = null;
		try {
			list = helper.getItemDao().queryForAll();
		} catch (SQLException e) {
			Log.e(TAG, "ERROR ITEMDAO: " + e.getMessage(), e);
		}
		return list;
	}

	@Override
	public Item findByID(int id) {

		return null;
	}

	@Override
	public void insert(Item object) {
		try {
			helper.getItemDao().create(object);
		} catch (SQLException e) {
			Log.e(TAG, "ERROR ITEMDAO: " + e.getMessage(), e);
		}
	}

	@Override
	public void update(Item object) {
		try {
			helper.getItemDao().update(object);
		} catch (SQLException e) {
			Log.e(TAG, "ERROR ITEMDAO: " + e.getMessage(), e);
		}
	}



}
